module.exports = function ($resource, $state, $http, $q, toaster, $modal) {
	return {
		scope: {
            linename: '=',
            xaxis: '=',
            data: '='
        },
        restrict: 'E',
        template: '<div></div>',
        replace: true,
		link: function (scope, element, attrs){

            var myChart = echarts.init(element[0]);

			var option = {
                title: {
                    text: '店铺会员变化趋势',
                    left: 'center',
                },
                tooltip : {
                    trigger: 'axis',
                    axisPointer : {
                        type : 'shadow'
                    }
                },
                grid: {
                    left: '3%',
                    right: '5%',
                    bottom: '3%',
                    containLabel: true
                },
                legend: {
                    data: scope.linename,
                    // orient: 'vertical',
                    // top: '5px',
                    x: 'right'
                },
                xAxis: [{
                    type: 'category',
                    data: scope.xaxis
                }],
                yAxis: [{
                    type: 'value',
                    name: '粉丝人数'
                }],
                color: ['#7266ba', '#23b7e5']
            };
            
            scope.$watch('data', function(newValue, oldValue){
                option.series = function(){
                    var serie = [
                        {'name': scope.linename[0], 'type': 'bar', 'stack': '总量', 'barWidth': '60%', 'data': scope.data[0]},
                        {'name': scope.linename[1], 'type': 'bar', 'stack': '总量', 'barWidth': '60%', 'data': scope.data[1]}
                    ];
                    return serie;  
                }();
                myChart.setOption(option);
            }, true);

		}
	};
};

